package com.lss.cloud.controller;


import com.lss.cloud.Resp.ResultData;
import com.lss.cloud.Resp.ReturnCodeEnum;
import com.lss.cloud.entities.PayDTO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * 2024/3/14-21:11
 * 功能:
 */
@RestController
@Slf4j
public class OrderController {
    public static final String PAYMENT_URL = "http://cloud-provider-payment-service";
    @Resource
    private RestTemplate restTemplate;
    @GetMapping("consumer/pay/add")
    public ResultData addOrder(PayDTO payDTO){

        return restTemplate.postForObject(PAYMENT_URL+"/pay/add",payDTO,ResultData.class);
    }
    @GetMapping("consumer/pay/get/{id}")
    public ResultData getOrderInfo(@PathVariable("id") Integer id){

        return restTemplate.getForObject(PAYMENT_URL+"/pay/get/"+id, ResultData.class,id);
    }
    @GetMapping("consumer/pay/del/{id}")
    public ResultData getOrderDel(@PathVariable("id") Integer id){
        restTemplate.delete(PAYMENT_URL+"/pay/del/"+id,id);
        return ResultData.failed(ReturnCodeEnum.RC401.getCode(), "failed");
    }
    @GetMapping("consumer/pay/update")
    public ResultData getOrderDel(PayDTO payDTO){
        restTemplate.put(PAYMENT_URL+"/pay/update",payDTO);
        return ResultData.success(null);
    }
    @GetMapping(value = "/consumer/pay/get/info")
    private String getInfoByConsul()
    {
        return restTemplate.getForObject(PAYMENT_URL + "/pay/get/info", String.class);
    }
}
